//
//  TimeTool.m
//  微blog
//
//  Created by Jorn.Wu on 15/8/24.
//  Copyright (c) 2015年 Jorn.Wu(jorn_wza@sina.com). All rights reserved.
//

#import "NSDateUtils.h"

@implementation NSDateUtils

/**
 * 通用，将字符串转为date
 */
+ (NSDate *)dateFromString:(NSString *)dateString withFormatterStr:(NSString *)formatterStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:formatterStr];
    
    NSDate *date = [formatter dateFromString:dateString];
    return date;
    
}

/**
 * 通用，将date转为字符串
 */
+ (NSString *)stringFromDate:(NSDate *)date withFormatterStr:(NSString *)formatterStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:formatterStr];
    NSString *dateString = [formatter stringFromDate:date];
    return dateString;
}

/**
 * 专用于该项目,把微薄创建时间 Fri Aug 28 00:00:00 +0800 2009 转化为 月-日 时:分 格式
 */
+ (NSString *)weiboDateString:(NSString *)string{
    
    NSString *formatterStr = @"E MMM dd HH:mm:ss Z yyyy";
    NSDate *date = [self dateFromString:string withFormatterStr:formatterStr];
    
    NSString *dateString = [self stringFromDate:date withFormatterStr:@"yyyy-MM-dd HH:mm"];
    return dateString;
    
}

@end
